package chapter_12


// 长方形对象

class Point(val x: Int, val y: Int)


trait Rectangular {

  def topLeft: Point
  def bottomRight: Point

  def left = topLeft.x
  def right = bottomRight.x
  def width = right - left
  // 以及其他更多的几何方法
}


abstract class Component extends Rectangular {
  // 其他方法
}


class Rectangle(val topLeft: Point, val bottomRight: Point)
  extends Rectangular {
  // 其他方法
}


object Rectangle {

  def main(args: Array[String]): Unit = {
    val rect = new Rectangle(new Point(1, 1), new Point(10, 10))
    println(rect.left)
    println(rect.right)
    println(rect.width)
  }
}